package fr.mairie.parc.control.materiel;

import java.util.ArrayList;
import java.util.List;

import org.apache.click.control.FieldSet;
import org.apache.click.control.Form;
import org.apache.click.control.Option;
import org.apache.click.control.Select;
import org.apache.click.control.TextField;
import org.apache.click.dataprovider.DataProvider;
import org.apache.click.extras.control.DoubleField;
import org.apache.click.extras.control.IntegerField;

import fr.mairie.parc.domain.Materiel;

public class MaterielFields {

		private FieldSet fieldset = new FieldSet("materielFieldset", "Materiel");
		private IntegerField idMateriel = new IntegerField("idMateriel", "ID",true);
		private TextField type = new TextField("type", "Type",true);
		private TextField marque = new TextField("marque", "Marque",true);
		private TextField modele = new TextField("modele", "Modéle",true);
		private Select stock = new Select("stock", "Stock",true);
		private DoubleField prix = new DoubleField("prix", "Prix",true);
		private IntegerField numParc = new IntegerField("numParc", "Numéro parc",true);
		private Select etat = new Select("etat", "Etat");

		@SuppressWarnings({ "serial", "rawtypes" })
		public MaterielFields () {

			fieldset.add(idMateriel);
			fieldset.add(type);
			fieldset.add(marque);
			fieldset.add(modele);
			stock.setDefaultOption(new Option("stock", "Choisir stock"));
			stock.setDataProvider(new DataProvider() {
	            @SuppressWarnings({ "unchecked" })
				public List getData() {
	                List optionList = new ArrayList();
	                optionList.add(new Option("Ville", "Stock ville"));
	                optionList.add(new Option("Ecole", "Stock école"));
	                optionList.add(new Option("Rebus", "Stock rebus"));
	                return optionList;
	            }
	        });
			fieldset.add(stock);
			fieldset.add(prix);
			/*fieldset.add(numParc);
			etat.setDefaultOption(new Option ("etat","Choisir l'état"));
			etat.setDataProvider(new DataProvider() {
				@SuppressWarnings("unchecked")
				public List getData() {
	                List optionList = new ArrayList();
	                optionList.add(new Option("disponible", "Disponible"));
	                optionList.add(new Option("nonDisponible", "Non disponible"));
	                return optionList;
	            }
			});
			fieldset.add(etat);*/
		}

		public void addAll(Form form) {
			form.add(fieldset);
		}

		public void setReadonly(boolean disabled) {
			fieldset.setReadonly(disabled);
		}

		public void getFieldsValues(Materiel in) {
			in.setIdMateriel(idMateriel.getInteger());
			in.setType(type.getValue());
			in.setMarque(marque.getValue());
			in.setModele(modele.getValue());
			in.setStock(stock.getValue());
			in.setPrix(prix.getDouble());
			in.setNumParc(numParc.getInteger());
			in.setEtat(etat.getValue());
		}

		public void setFieldsValues(Materiel src) {
			idMateriel.setInteger(src.getIdMateriel());
			type.setValue(src.getType());
			marque.setValue(src.getMarque());
			modele.setValue(src.getModele());
			stock.setValue(src.getStock());
			prix.setDouble(src.getPrix());
			numParc.setInteger(src.getNumParc());
			etat.setValue(src.getEtat());
		}

		public void setIdMateriel(Materiel src) {
			idMateriel.setInteger(src.getIdMateriel());
		}

		public int getIdMateriel() {
			return idMateriel.getInteger();
		}




}
